package com.tomvian.screens.transitions 
{
	import com.tomvian.screens.AbstractScreen;
	import com.tomvian.screens.AbstractTransition;
	import org.libspark.betweenas3.BetweenAS3;
	import org.libspark.betweenas3.easing.Quad;
	import org.libspark.betweenas3.tweens.ITween;
	/**
	 * SlideIn
	 * @author Tom Vian
	 */
	public class SlideIn extends AbstractTransition
	{
		//--------------------------------------------------------------------------
		//
		//  Properties
		//
		//--------------------------------------------------------------------------
		
		protected var _tween:ITween;
		
		protected var _outPos:Object;
		protected var _inPos:Object;
		
		protected var _time:Number;
		
		//--------------------------------------------------------------------------
		//
		//  Getters / Setters
		//
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//
		//  Constructor
		//
		//--------------------------------------------------------------------------
		
		public function SlideIn(time:Number = 0.5, stageWidth:Number = 800.0, fromLeft:Boolean = false) 
		{
			_time = time;
			
			_outPos = { x: fromLeft ? -stageWidth : stageWidth };
			_inPos = { x: 0 };
		}
		
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		override public function play(fromScreen:AbstractScreen, toScreen:AbstractScreen):void 
		{
			super.play(fromScreen, toScreen);
			
			swap();
			
			if (_tween) _tween.stop();
			_tween = BetweenAS3.tween(_toScreen.graphic, _inPos, _outPos, _time, Quad.easeInOut);
			_tween.onComplete = onTransitionComplete;
			_tween.play();
		}
	}
}